# pragma once

//int* p = new int;
//checked_delete(p);

//char *a = new char[10];
//checked_array_delete(a);


//thanks boost/checked_delete.hpp

template<class T> inline void checked_delete(T * x) noexcept
{
    typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
    (void) sizeof(type_must_be_complete);
    delete x;
}

template<class T> inline void checked_array_delete(T * x) noexcept
{
    typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
    (void) sizeof(type_must_be_complete);
    delete [] x;
}

template<class T> struct checked_deleter
{
    typedef void result_type;
    typedef T * argument_type;

    void operator()(T * x) const noexcept
    {
        checked_delete(x);
    }
};

template<class T> struct checked_array_deleter
{
    typedef void result_type;
    typedef T * argument_type;

    void operator()(T * x) const noexcept
    {
        checked_array_delete(x);
    }
};

#if 0
#include "checked_delete.h"

int main()
{
        int* p = new int;
        // check_delete(p);
        // boost::checked_deleter<int>()(p);
        checked_delete(p);

        char *a = new char[10];
        // check_array_delete(a);
        // boost::checked_array_deleter<char>()(a);
        checked_array_delete(a);

}
#endif
